package com.wp.productservice8090.controller;

import com.wp.dto.ProductDTO;
import com.wp.productservice8090.service.ProductServcie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.HashMap;
import java.util.Map;

/**
 * productcontroller
 *
 * @author wp
 * @date 2020 / 10 / 14 : 15:36
 **/
@RestController
@RequestMapping(name = "/product")
public class ProductController {

    @Autowired
    ProductServcie productServcie;

    @GetMapping(name = "/list")
    public ResponseEntity productList() {
        Map<String, Object> map = new HashMap<>();

        return ResponseEntity.ok(map);
    }

    @PostMapping(name = "/add")
    public ResponseEntity addProduct(@Valid @RequestBody ProductDTO dto) {

        productServcie.addProduct(dto);

        Map<String, Object> map = new HashMap<>();
        map.put("msg", "success");
        return ResponseEntity.ok(map);
    }
}
